import { reqGetGoodDetailInfoData } from "@/api"

const state={

goodDetailInfo:{

}


}
const actions={
//获取详细数据
async getDetailInfoData({commit},id){
  const res=await reqGetGoodDetailInfoData(id)
  if(res.code===200){
    commit('SAVE_DETAIL_INFO_DATA',res.data)
  }else{
    console.log(res.data)
  }
}


}
const mutations={
  //存储详情数据
  SAVE_DETAIL_INFO_DATA(state,goodDetailInfo){
    state.goodDetailInfo=goodDetailInfo
  },
//将小图付给大图
UPDATE_SKUINFO_DEFAULT_IMGURL(state,skuImg) {
  // 2.1 循环遍历图片列表，先将所有的isDefault设置为0
  state.goodDetailInfo.skuInfo.skuImageList.forEach(item => {
    item.isDefault = '0'
  })
  // 2.2 当前被单击的小图片要设置成高亮
  skuImg.isDefault = '1'
  // 2.3 实现小图切换大图 也就是将被单击的小图的链接给到大图链接 
  state.goodDetailInfo.skuInfo.skuDefaultImg = skuImg.imgUrl
}


}
const getters={

  categoryView(state){
    return state.goodDetailInfo.categoryView||{}
  },
  skuInfo(state){
return state.goodDetailInfo.skuInfo||{}
  },
  spuSaleAttrList(state){
    return state.goodDetailInfo.spuSaleAttrList||[]
  }
}
export default{
  namespaced:true,
  state,
  actions,
  mutations,
  getters,
}